package serivce

import (
	"context"
	"errors"
	"petCombo-srv/dao"
	"petCombo-srv/internal/model"
	__ "petCombo-srv/proto"
)

func (p *Pets) Order(_ context.Context, in *__.OrderReq) (*__.OrderResp, error) {

	if in.UserId <= 0 || in.ComboId <= 0 {
		return nil, errors.New("参数错误")
	}

	orderService := dao.NewOrderService()
	err := orderService.Order(model.Order{
		ComboId: int(in.ComboId),
		UserId:  int(in.UserId),
		Price:   int(in.Price),
		Number:  1,
	})
	if err != nil {
		return nil, err
	}

	return &__.OrderResp{
		OrderId: 1,
	}, nil
}
